package com.example.demo.Controller;

import com.alibaba.druid.pool.DruidDataSource;
import com.example.demo.Config.DBConfig;
import com.example.demo.Domain.ResponseJson;
import com.example.demo.Domain.ResponseResult;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

@RestController
@EnableAutoConfiguration
public class HelloController {

    @RequestMapping(value = "/hello")
    public String hello() {
        return "hello,Spring Boot";
    }
    @RequestMapping(value = "/get")
    public Object get() throws SQLException {

        DruidDataSource d= DBConfig.GetDataSource();
        Connection c= d.getConnection();
        Statement stm= c.createStatement();
        ResultSet rs= stm.executeQuery("select * from dist_department");
        rs.last();
        ResponseJson responseJson=new ResponseJson();
        responseJson.setData(rs.getString(1));
        responseJson.setDataCount(rs.getRow());
        responseJson.setResult(ResponseResult.OK);

        StringBuilder sb=new StringBuilder();
        sb.append("共有");
        sb.append(String.valueOf(rs.getRow()));
        sb.append("行");
        responseJson.setMsg(sb.toString());
        return  responseJson;
    }
}
